﻿using System.Collections.Generic;
using Xenta.Api;
using Xenta.Plugins;
using Xenta.Structs;

namespace Xenta.Operations
{
    /// <summary>
    /// Gets the list of registered dependencies.
    /// </summary>
    /// <typeparam name="TDependency">The service interface to check.</typeparam>
    public class ListDependencies<TDependency> : Operation<IEnumerable<DependencyInfo>>
        where TDependency : IDependency
    {
        #region Utilities

        protected override void Work(IUnitOfWork uow, out IEnumerable<DependencyInfo> result)
        {
            result = uow.Infrastructure.ListDependencies<TDependency>();
        }

        #endregion
    }

    /// <summary>
    /// Gets the list of registered import/export formats.
    /// </summary>
    public class ListImportExportFormats : ListDependencies<IImportExportFormat>,
        IApiOperation
    {
    }

    /// <summary>
    /// Gets the registered dependency.
    /// </summary>
    public class GetDependency : Operation<DependencyInfo?>,
        IApiOperation
    {
        #region Properties

        /// <summary>
        /// Gets or sets the component global-unique identifier.
        /// </summary>
        public string ID
        {
            get;
            set;
        }

        #endregion

        #region Utilities

        protected override void Work(IUnitOfWork uow, out DependencyInfo? result)
        {
            result = uow.Infrastructure.DependencyInfo(ID);
        }

        #endregion
    }
}
